package com.lhd.entity.query;
import com.lhd.entity.enums.PageSize;
public class SimplePage {
	// 页号
	private Long pageNo;

	// 查询结果中有多少条记录 通过它算出结果有多少页
	private Long resultCount;

	// 一页多大
	private Long pageSize;

	// 总共查出来多少页
	private Long pageTotal;

	// limit的起始索引
	private Long start;

	// limit的偏移量
	private Long end;

	public SimplePage() {
	}

	public SimplePage(Long pageNo, Long resultCount, Long pageSize) {
		if (null == pageNo) {
			pageNo = 0L;
		}
		this.pageNo = pageNo;
		this.resultCount = resultCount;
		this.pageSize = pageSize;
		action();
	}

	public SimplePage(Long start, Long end) {
		this.start = start;
		this.end = end;
	}

	public void action() {
		if (this.pageSize <= 0) {
			this.pageSize = (long) PageSize.SIZE20.getSize();
		}
		// 计算结果有多少页
		if (this.resultCount > 0) {
			this.pageTotal = this.resultCount % this.pageSize == 0 ? this.resultCount / this.pageSize
					: this.resultCount / this.pageSize + 1;
		} else {
			pageTotal = 1L;
		}

		if (pageNo <= 1) {
			pageNo = 1L;
		}
		// 如果想要的页号比查出来的页还大
		if (pageNo > pageTotal) {
			pageNo = pageTotal;
		}

		this.start = (pageNo - 1) * pageSize;
		this.end = this.pageSize;
	}

	public Long getPageNo() {
		return pageNo;
	}

	public void setPageNo(Long pageNo) {
		this.pageNo = pageNo;
	}

	public Long getResultCount() {
		return resultCount;
	}

	public void setResultCount(Long resultCount) {
		this.resultCount = resultCount;
		this.action();
	}

	public Long getPageSize() {
		return pageSize;
	}

	public void setPageSize(Long pageSize) {
		this.pageSize = pageSize;
	}

	public Long getPageTotal() {
		return pageTotal;
	}

	public void setPageTotal(Long pageTotal) {
		this.pageTotal = pageTotal;
	}

	public Long getStart() {
		return start;
	}

	public void setStart(Long start) {
		this.start = start;
	}

	public Long getEnd() {
		return end;
	}

	public void setEnd(Long end) {
		this.end = end;
	}
}
